package ane
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.StatusEvent;
	import flash.external.ExtensionContext;
	
	/**
	 * <br> 클래스 설명 : </br>
	 * @author 김정환
	 */	
	public class AneInterfaceManager extends EventDispatcher
	{
		
		//-----------------------------------------------------------------------------------
		// singleton
		//-----------------------------------------------------------------------------------
		
		private static var _instance : AneInterfaceManager;
		
		public static function getInstance():AneInterfaceManager
		{
			if( _instance == null ) _instance = new AneInterfaceManager;
			
			return _instance;
		}
		
		
		
		
		
		//-----------------------------------------------------------------------------------
		// public vars
		//-----------------------------------------------------------------------------------
		
		
		
		
		//-----------------------------------------------------------------------------------
		// protected / internal vars
		//-----------------------------------------------------------------------------------
		
		
		
		
		//-----------------------------------------------------------------------------------
		// private vars
		//-----------------------------------------------------------------------------------
		
		
		private var _context:ExtensionContext;
		
		//-----------------------------------------------------------------------------------
		// public functions
		//-----------------------------------------------------------------------------------
		
		/**
		 * constructor 
		 */	
		public function AneInterfaceManager()
		{
			_context = ExtensionContext.createExtensionContext("com.xprime.mobileFramework", null);
			trace(" ==> AneInterfaceManager AneInterfaceManager : " + _context );
			
			_context.addEventListener( StatusEvent.STATUS, onStatusHandler );
		}
		
		
		public function toast(pValue:String):Object 
		{				
			return this.call("toast", pValue);			
		}
		
		public function alertDialog(pTitle:String,pMessage:String):Object 
		{
			return call("alertDialog", pTitle, pMessage);			
		}
		
		public function timePickerDialog():Object 
		{
			return call("timerPickerDialog");
		}

		public function itemListDialog(pTitle:String,pValue:String):Object 
		{
			return call("itemListDialog", pTitle, pValue );			
		}
		
		public function fileOpenExtension( fileName:String, fullPath : String ): Object
		{
			return call("fileOpenExtension", fileName, fullPath );
		}
		
		public function fileDownLoadExtension( fileName:String, downloadFolder : String, fullURL : String ): Object
		{
			return call("fileDownloadExtension", fileName, downloadFolder, fullURL );
		}
		
		/**
		 * @param fullPath - 파일의 경로 ( 경로는 /sdcard/ 다음부터 )
		 * @return Boolean
		 */		
		public function isFile( fullPath : String ): Boolean
		{
			return call("isFile", fullPath ) as Boolean;
		}
		
		
		/**
		 * @param isOn
		 * @param title
		 * @param message
		 * @return String 
		 */		
		public function loading( isOn : Boolean, title:String="", message : String="" ):String
		{
			return call( "loading", isOn, title, message ) as String;
		}
		
		
		//-----------------------------------------------------------------------------------
		// setter / getter
		//-----------------------------------------------------------------------------------
		
		
		
		//-----------------------------------------------------------------------------------
		// protected functions
		//-----------------------------------------------------------------------------------
		
		
		
		//-----------------------------------------------------------------------------------
		// internal functions
		//-----------------------------------------------------------------------------------
		
		
		
		
		//-----------------------------------------------------------------------------------
		// private functions
		//-----------------------------------------------------------------------------------
		
		
		private function call(pName:String , ...args:Array):Object 
		{			
			if (this._context == null)
			{
				return null;
			}
			return this._context.call.apply( this , [pName].concat(args) ); 
		}
		
		//-----------------------------------------------------------------------------------
		// event handler
		//-----------------------------------------------------------------------------------
		
		
		
		protected function onStatusHandler(e:Event):void
		{
			this.dispatchEvent( e.clone() );
		}
		
		
		
		
		
		
		
	}
}